{template 'common/header'}





<style>
    .calendar-time select {
        width: 83px !important;
        margin-bottom: 0;
    }
</style>

<ul class="nav nav-tabs">

    <li {if $op == 'add'} class="active"{/if}><a href="{php echo $this->createWebUrl('SpaceRentalProductManage', array('op' => 'add'))}">添加产品</a></li>
    <li {if $op == 'display'} class="active"{/if}><a href="{php echo $this->createWebUrl('SpaceRentalProductManage', array('op' => 'display'))}">产品管理</a></li>

</ul>
<style>
    .label{line-height: 2}
    .danger{position: relative}
</style>
{if $op == 'display'}

<div class="panel panel-default">
    <div class="panel-heading">筛选</div>
    <div class="panel-body">
        <form action="./index.php" method="get" class="form-horizontal" role="form" id="form">
            <input type="hidden" name="c" value="site">
            <input type="hidden" name="a" value="entry">
            <input type="hidden" name="m" value="orange_storemanage">
            <input type="hidden" name="do" value="storesort">
            <input type="hidden" name="token" value="{$_W['token']}">
            <input type="hidden" name="op" value="storebrandmanage">
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">产品名[模糊搜索]</label>
                <div class="col-sm-8 col-xs-12">
                    <input type="text" class="form-control" name="keyword" value="{$_GPC['keyword']}" />
                </div>
                <div class="pull-right col-xs-12 col-sm-3 col-md-2 col-lg-2">
                    <input type="submit" class="btn btn-primary span3" name="submit" value="搜索" />
                </div>
            </div>
        </form>
    </div>
</div>
<div class="panel panel-default">
    <div class="panel-body table-responsive">
        <table class="table table-hover">
            <thead>
            <tr>
                <th width="50">ID</th>
                <th width="180">产品名</th>
                <th width="180">对应租赁空间</th>
                <th width="150">创建时间</th>
                <!--<th width="140">状态</th>-->
                <th width="80" class="text-right">操作</th>
            </tr>
            </thead>
            {loop $list $row}
            <tr>
                <td>
                    {$row['id']}
                </td>
                <td>
                    {$row['pro_name']}
                </td>

                <td>
                    <span class="label label-danger js-status">  {php echo $this->getSpaceNameById($row['space_id']);}</span>
                </td>

                <td>{php echo date('Y-m-d H:i', $row['create_time']);}</td>
                <td class="text-right">
                    <a href="javascript:void(0);" attr-space_id = "{$row['space_id']}" attr-pro_id="{$row['id']}" onclick="deleteAttr(this)" id="js-delete" title="" class="btn btn-default">删除</a>
                </td>
                {/loop}
        </table>
    </div>
</div>
{$pager}


<script type="text/javascript">

    function deleteAttr(_this) {
        var r=confirm("是否确认删除?");
        if(r == true)
        {
            //产品主键id
            var pro_id = $(_this).attr('attr-pro_id');
            //对应租赁空间id
            var space_id = $(_this).attr('attr-space_id');
            $.post("{php echo $this->createWeburl('SpaceRentalProductManage', array('op' => 'delete'))}",
                {'pro_id' : pro_id,'space_id':space_id},
                function(data) {
                    var data = JSON.parse(data);
                    if(data.errCode == 0){
                        util.message(data.msg, 'refresh', 'success');
                    }else{
                        util.message(data.msg, 'refresh', 'error');
                    }
                });
        }
    }

    function updateStatus(_status,_this) {
        var _status = _status;
        var id = $(_this).attr('attr-id');

        $.post("{php echo $this->createWeburl('storebrandmanage', array('op' => 'change_status'))}",
            {'id' : id,'status':_status},
            function(data) {
                var data = JSON.parse(data);
                if(data.errCode == 0){
                    util.message('更新成功', 'refresh', 'success');
//                util.message('删除成功', 'refresh', 'success');
                }else{
                    util.message('更新失败', '', 'error');
                }
            });
    }

    $(document).ready(function () {

        $(".changeValue").change(function () {
            var r=confirm("是否确认更改此属性名?");
            if(r == true){
                var _value = $(this).val();
                var id = $(this).attr('attr-id');
                $.post("{php echo $this->createWeburl('attrmanage', array('op' => 'edit'))}",
                    {'id' : id,'value':_value},
                    function(data) {
                        var data = JSON.parse(data);
                        if(data.errCode == 0){
                            util.message('更新成功', 'refresh', 'success');
                            //                util.message('删除成功', 'refresh', 'success');
                        }else{
                            util.message('更新失败', '', 'error');
                            $('#ajaxForm')[0].reset();
                        }
                    });
            }else{
                $('#ajaxForm')[0].reset();
            }
        })
    })

</script>


{elseif $op == 'add'}
    <div class="panel panel-default"  id="input_body">
        <div class="panel-heading">
            添加产品
        </div>

        <div class="panel-body">
            <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" id="form1">


            <!--<div class="form-group">-->
                <!--<label class="col-xs-12 col-sm-3 col-md-2 control-label">产品名<span style="color:red">*</span></label>-->
                <!--<div class="col-sm-9 col-xs-12">-->
                    <!--<input required=""  type="text" attr-name="属性名" name="pro_name" value="" class="form-control">-->

                <!--</div>-->
            <!--</div>-->

            <div class="form-group">

                <label class="col-xs-12 col-sm-3 col-md-2 control-label">租赁空间<span style="color:red">*</span></label>
                <div class="col-sm-9 col-xs-12">
                    <select class="form-control" name="space_id" id="">
                        <option name="" value="">--请选择对应的租赁空间--</option>
                        {loop $spaceList $space}
                            <option name="" value="{$space['id']}">{$space['space_name']}</option>
                        {/loop}
                    </select>
                </div>

                <input type="hidden" name="token" value="{$_W['token']}" />
            </div>


                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">计费方式<span style="color:red">*</span></label>
                    <div class="col-sm-9 col-xs-12">

                        <label class="radio-inline">
                            <input type="radio" name="payType"  value="option1"> 按时间计费
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="payType" value="option2"> 按次数计费
                        </label>

                    </div>
                </div>


                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">收费方式<span style="color:red">*</span></label>

                    <div class="col-sm-9 col-xs-12">

                        <label class="checkbox-inline">
                            <input type="checkbox" name="charge_type[]" value="1"> 按时间计费
                        </label>
                        <label class="checkbox-inline">
                            <input type="checkbox" name="charge_type[]" value="2"> 按次数计费
                        </label>
                    </div>
                </div>


                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否免费<span style="color:red">*</span></label>
                    <div class="col-sm-9 col-xs-12">

                        <label class="radio-inline">
                            <input type="radio" name="isfree"  value="1"> 是
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="isfree"  value="0"> 否
                        </label>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">计时间隔<span style="color:red">*</span></label>
                    <div class="col-sm-9 col-xs-12">


                        <select class="form-control" id="charge_time" name="chargeTime" id="">
                            <option  value="">--请选择计时间隔--</option>
                            <option  value="30">30分钟</option>
                            <option  value="15">15分钟</option>
                            <option  value="60">60分钟</option>
                        </select>
                    </div>
                </div>


                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red"></span></label>
                    <div class="col-sm-9 col-xs-9" id="timeCheck">

                    </div>
                </div>
            </form>

            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                <div class="col-sm-9 col-xs-12">
                    <button onclick="add()" class="btn btn-primary col-lg-1" value="提交">提交</button>
                </div>
            </div>

        </div>
    </div>


<script>

    // 将分钟数量转换为小时和分钟字符串
    function toHourMinute(minutes){
        var _h = Math.floor(minutes/60);
        var _m = minutes%60;
        if(_m<10){
            _m = _m + '0';
        }
        if(_h<10)
        {
            _h = '0' + _h;
        }
        return ( _h+ ":" + _m );
        // 也可以转换为json，以方便外部使用
        // return {hour:Math.floor(minutes/60),minute:(minutes%60)};
    }


    $("select#charge_time").change(function(){
         var _chargeTime = $(this).val();
         var _em = 1440/_chargeTime;
         var _html = '';
         for($i=0;$i<=_em;$i++)
         {
             var t = toHourMinute($i*_chargeTime);
             var _html= _html + ' <label style="margin-left: 10px" class="checkbox-inline"><input type="checkbox" checked name="sel_time[]" value="1">'+t+'</label>';
         }

        _html = '<div class="alert alert-success" role="alert"><strong>选择时间间隔成功! </strong> 请选择该租赁空间开放租赁的时间 </div>'+_html;
        $("#timeCheck").html(_html);


    });
</script>


<script>


    require(['bootstrap.switch'],function($){
        $('.js-flag:checkbox').bootstrapSwitch(
            {
                onColor:'success',
                onText: '启用',
                offText: '关闭',
                size:"small",
            });


//        $('.js-flag:checkbox').on('switchChange.bootstrapSwitch', function(event, state) {
//            var id = $(this).data('id');
//            var ban = state ? 1 : 0;
//            $.getJSON("{php echo $this->createWeburl('couponexchange', array('op' => 'change_status'))}", {id:id, status:ban}, function(data) {
//                var data = eval(data.message);
//            });
//        });
    });


    function add() {
        var obj =  $('form').serializeArray();
        var _data = {};
        $(obj).each(function (i) {
            _data[this.name] = this.value;
        });
        $.post("{php echo $this->createWeburl('SpaceRentalProductManage', array('op' => 'add'))}",
            _data,
            function(data) {
                if(data.errCode == 0){
                    util.message(data.msg, 'refresh', 'success');
                }else{
                    util.message(data.msg,'','error');
                }
                },"JSON");
    }
</script>



<script>
/*
    $("select#sort-select").change(function(){
        var _type_id = $(this).val();
        $.post("{php echo $this->createWeburl('storebrandmanage', array('op' => 'getfurthersort'))}",
            {'type_id':_type_id},

            function(data) {
                var data = JSON.parse(data);
                if(data.errCode == 0){

                    var content = JSON.parse(data.content);
                    var html = '<option value="">--请选择--</option>';
                    $.each(content,function (i) {
                        html += '<option value="'+content[i].id+'">'+content[i].value+'</option>'
                    })
                    $('#further-select').html(html);
                }else{
                }
            });
    });
*/
</script>

{elseif $op == 'storebrandmanage'}
<div class="panel panel-default">
    <div class="panel-heading">筛选</div>
    <div class="panel-body">
        <form action="./index.php" method="get" class="form-horizontal" role="form" id="form">
            <input type="hidden" name="c" value="site">
            <input type="hidden" name="a" value="entry">
            <input type="hidden" name="m" value="orange_storemanage">
            <input type="hidden" name="do" value="storesort">
            <input type="hidden" name="token" value="{$_W['token']}">
            <input type="hidden" name="op" value="storebrandmanage">
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">品牌名[模糊搜索]</label>
                <div class="col-sm-8 col-xs-12">
                    <input type="text" class="form-control" name="keyword" value="{$_GPC['keyword']}" />
                </div>
                <div class="pull-right col-xs-12 col-sm-3 col-md-2 col-lg-2">
                    <input type="submit" class="btn btn-primary span3" name="submit" value="搜索" />
                </div>
            </div>
        </form>
    </div>
</div>
<div class="panel panel-default">
    <div class="panel-body table-responsive">
        <table class="table table-hover">
            <thead>
            <tr>
                <th width="50">ID</th>
                <th width="180">品牌名</th>
                <th width="180">所属</th>
                <th width="150">创建时间</th>
                <!--<th width="140">状态</th>-->
                <th width="80" class="text-right">操作</th>
            </tr>
            </thead>
            {loop $list $row}
            <tr>
                <td>
                    {$row['id']}
                </td>
                <form action="" id="ajaxForm">
                    <td>
                        <input id="changeValue" attr-id="{$row['id']}" class="form-control" type="text" value="{$row['value']}">
                    </td>
                </form>

                <td>
                    {php echo $this->getFurtherSortById($row['furthersort_id']);}
                </td>
                <td>{php echo date('Y-m-d H:i', $row['create_time']);}</td>

                <!--
             <td>
                {if $row['status'] == 2}
                    <span onclick="updateStatus(1,this)" attr-id="{$row['id']}" class="label label-danger js-status">禁用 (点击开启)</span>
                {else}
                    <span onclick="updateStatus(2,this)" attr-id="{$row['id']}" class="label label-success js-status">正常 (点击禁用)</span>
                {/if}
            </td>
            !-->


            <td class="text-right">
                <a href="javascript:void(0);" attr-id="{$row['id']}" onclick="deleteSort(this)" id="js-delete" title="编辑店铺" class="btn btn-default">删除</a>
            </td>
            {/loop}
        </table>
    </div>
</div>
{$pager}


<script type="text/javascript">
    
    function deleteSort(_this) {
        var r=confirm("是否确认删除?");
        if(r == true)
        {
            var id = $(_this).attr('attr-id');
            $.post("{php echo $this->createWeburl('storebrandmanage', array('op' => 'delete'))}",
                {'id' : id},
                function(data) {
                    var data = JSON.parse(data);
                    if(data.errCode == 0){
                        util.message(data.msg, 'refresh', 'success');
                    }else{
                        util.message(data.msg, 'refresh', 'error');
                    }
                });
        }
    }

    function updateStatus(_status,_this) {
        var _status = _status;
        var id = $(_this).attr('attr-id');

        $.post("{php echo $this->createWeburl('storebrandmanage', array('op' => 'change_status'))}",
            {'id' : id,'status':_status},
            function(data) {
                var data = JSON.parse(data);
                if(data.errCode == 0){
                    util.message('更新成功', 'refresh', 'success');
//                util.message('删除成功', 'refresh', 'success');
                }else{
                    util.message('更新失败', '', 'error');
                }
            });
    }

    $(document).ready(function () {

        $("#changeValue").change(function () {
            var r=confirm("是否确认更改此品牌名?");
            if(r == true){
                var _value = $(this).val();
                var id = $(this).attr('attr-id');
                $.post("{php echo $this->createWeburl('storebrandmanage', array('op' => 'edit'))}",
                    {'id' : id,'value':_value},
                    function(data) {
                        var data = JSON.parse(data);
                        if(data.errCode == 0){
                            util.message('更新成功', 'refresh', 'success');
                            //                util.message('删除成功', 'refresh', 'success');
                        }else{
                            util.message('更新失败', '', 'error');
                            $('#ajaxForm')[0].reset();
                        }
                    });
            }else{
                $('#ajaxForm')[0].reset();
            }
        })
    })

</script>


{elseif $op == 'storepositionmanage'}
<div class="panel panel-default">
    <div class="panel-heading">筛选</div>
    <div class="panel-body">
        <form action="./index.php" method="get" class="form-horizontal" role="form" id="form">
            <input type="hidden" name="c" value="site">
            <input type="hidden" name="a" value="entry">
            <input type="hidden" name="m" value="orange_storemanage">
            <input type="hidden" name="do" value="storesort">
            <input type="hidden" name="token" value="{$_W['token']}">
            <input type="hidden" name="op" value="storepositionmanage">
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">位置[模糊搜索]</label>
                <div class="col-sm-8 col-xs-12">
                    <input type="text" class="form-control" name="keyword" value="{$_GPC['keyword']}" />
                </div>
                <div class="pull-right col-xs-12 col-sm-3 col-md-2 col-lg-2">
                    <input type="submit" class="btn btn-primary span3" name="submit" value="搜索" />
                </div>
            </div>
        </form>
    </div>
</div>
<div class="panel panel-default">
    <div class="panel-body table-responsive">
        <table class="table table-hover">
            <thead>
            <tr>
                <th width="50">ID</th>
                <th width="180">位置名</th>
                <th width="180">所属</th>
                <th width="150">创建时间</th>
                <!--<th width="140">状态</th>-->
                <th width="80" class="text-right">操作</th>
            </tr>
            </thead>
            {loop $list $row}
            <tr>
                <td>
                    {$row['id']}
                </td>
                <form action="" id="ajaxForm">
                <td>
                    <input id="changeValue" attr-id="{$row['id']}" class="form-control" type="text" value="{$row['value']}">
                </td>
                </form>

                <td>
                    {php echo $this->getFurtherSortById($row['furthersort_id']);}
                </td>
                <td>{php echo date('Y-m-d H:i', $row['create_time']);}</td>
                <!--
                               <td>
                                   {if $row['status'] == 2}
                                   <span onclick="updatePosition(1,this)" attr-id="{$row['id']}" class="label label-danger js-status">禁用 (点击开启)</span>
                                   {else}
                                   <span onclick="updatePosition(2,this)" attr-id="{$row['id']}" class="label label-success js-status">正常 (点击禁用)</span>
                                   {/if}
                               </td>
                !-->
                               <td class="text-right">
                                   <a href="javascript:void(0);" attr-id="{$row['id']}" onclick="deletePosition(this)"  title="" class="btn btn-default">删除</a>

                               </td>
                               {/loop}
                       </table>
                   </div>
               </div>
               {$pager}


               <script type="text/javascript">

                   function deletePosition(_this) {
                       var r=confirm("是否确认删除?");
                       if(r == true)
                       {
                           var id = $(_this).attr('attr-id');
                           $.post("{php echo $this->createWeburl('storepositionmanage', array('op' => 'delete'))}",
                               {'id' : id},
                               function(data) {
                                   var data = JSON.parse(data);
                                   if(data.errCode == 0){
                                       util.message(data.msg, 'refresh', 'success');
                                   }else{
                                       util.message(data.msg, 'refresh', 'error');
                                   }
                               });
                       }
                   }

                   function updatePosition(_status,_this) {
                       var _status = _status;
                       var id = $(_this).attr('attr-id');
                       $.post("{php echo $this->createWeburl('storepositionmanage', array('op' => 'change_status'))}",
                           {'id' : id,'status':_status},
                           function(data) {
                               var data = JSON.parse(data);
                               if(data.errCode == 0){
                                   util.message('更新成功', 'refresh', 'success');
               //                util.message('删除成功', 'refresh', 'success');
                               }else{
                                   util.message('更新失败', '', 'error');
                               }
                       });
                   }

                   $(document).ready(function () {

                       $("#changeValue").change(function () {
                           var r=confirm("是否确认更改此位置名?");
                           if(r == true){
                               var _value = $(this).val();
                               var id = $(this).attr('attr-id');
                               $.post("{php echo $this->createWeburl('storepositionmanage', array('op' => 'edit'))}",
                                   {'id' : id,'value':_value},
                                   function(data) {
                                       var data = JSON.parse(data);
                                       if(data.errCode == 0){
                                           util.message('更新成功', 'refresh', 'success');
                   //                util.message('删除成功', 'refresh', 'success');
                                       }else{
                                           util.message('更新失败', '', 'error');
                                           $('#ajaxForm')[0].reset();
                                       }
                               });
                           }else{
                               $('#ajaxForm')[0].reset();
                           }
                       })
                   })

               </script>
               {elseif $op == 'storenumbermanage'}
               <div class="panel panel-default">
                   <div class="panel-heading">筛选</div>
                   <div class="panel-body">
                       <form action="./index.php" method="get" class="form-horizontal" role="form" id="form">
                           <input type="hidden" name="c" value="site">
                           <input type="hidden" name="a" value="entry">
                           <input type="hidden" name="m" value="orange_storemanage">
                           <input type="hidden" name="do" value="storesort">
                           <input type="hidden" name="token" value="{$_W['token']}">
                           <input type="hidden" name="op" value="storenumbermanage">
                           <div class="form-group">
                               <label class="col-xs-12 col-sm-3 col-md-2 control-label">店铺号[模糊搜索]</label>
                               <div class="col-sm-8 col-xs-12">
                                   <input type="text" class="form-control" name="keyword" value="{$_GPC['keyword']}" />
                               </div>
                               <div class="pull-right col-xs-12 col-sm-3 col-md-2 col-lg-2">
                                   <input type="submit" class="btn btn-primary span3" name="submit" value="搜索" />
                               </div>
                           </div>
                       </form>
                   </div>
               </div>
               <div class="panel panel-default">
                   <div class="panel-body table-responsive">
                       <table class="table table-hover">
                           <thead>
                           <tr>
                               <th width="50">ID</th>
                               <th width="180">店铺号</th>
                               <th width="180">所属</th>
                               <th width="150">创建时间</th>
                               <!--<th width="140">状态</th>-->
                               <th width="80" class="text-right">操作</th>
                           </tr>
                           </thead>
                           {loop $list $row}
                           <tr>
                               <td>
                                   {$row['id']}
                               </td>
                               <form action="" id="ajaxForm">
                                   <td>
                                       <input id="changeValue" attr-id="{$row['id']}" class="form-control" type="text" value="{$row['value']}">
                                   </td>
                               </form>


                               <td>
                                   {php echo $this->getFurtherSortById($row['furthersort_id']);}
                               </td>
                               <td>{php echo date('Y-m-d H:i', $row['create_time']);}</td>
                                <!--
                               <td>
                                   {if $row['status'] == 2}
                                   <span onclick="updateNumber(1,this)" attr-id="{$row['id']}" class="label label-danger js-status">禁用 (点击开启)</span>
                                   {else}
                                   <span onclick="updateNumber(2,this)" attr-id="{$row['id']}" class="label label-success js-status">正常 (点击禁用)</span>
                                   {/if}
                               </td>
                                !-->
                               <td class="text-right">
                                   <a href="javascript:void(0);" attr-id="{$row['id']}" onclick="deleteNumber(this)"  title="" class="btn btn-default">删除</a>

                               </td>
                               {/loop}
                       </table>
                   </div>
               </div>
               {$pager}


               <script type="text/javascript">

                   function deleteNumber(_this) {
                       var r=confirm("是否确认删除?");
                       if(r == true)
                       {
                           var id = $(_this).attr('attr-id');
                           $.post("{php echo $this->createWeburl('storenumbermanage', array('op' => 'delete'))}",
                               {'id' : id},
                               function(data) {
                                   var data = JSON.parse(data);
                                   if(data.errCode == 0){
                                       util.message(data.msg, 'refresh', 'success');
                                   }else{
                                       util.message(data.msg, 'refresh', 'error');
                                   }
                               });
                       }
                   }

                   function updateNumber(_status,_this) {
                       var _status = _status;
                       var id = $(_this).attr('attr-id');
                       $.post("{php echo $this->createWeburl('storenumbermanage', array('op' => 'change_status'))}",
                           {'id' : id,'status':_status},
                           function(data) {
                               var data = JSON.parse(data);
                               if(data.errCode == 0){
                                   util.message('更新成功', 'refresh', 'success');
               //                util.message('删除成功', 'refresh', 'success');
                               }else{
                                   util.message('更新失败', '', 'error');
                               }
                           });
                   }

                   $(document).ready(function () {

                       $("#changeValue").change(function () {
                           var r=confirm("是否确认更改此位置名?");
                           if(r == true){
                               var _value = $(this).val();
                               var id = $(this).attr('attr-id');
                               $.post("{php echo $this->createWeburl('storenumbermanage', array('op' => 'edit'))}",
                                   {'id' : id,'value':_value},
                                   function(data) {
                                       var data = JSON.parse(data);
                                       if(data.errCode == 0){
                                           util.message('更新成功', 'refresh', 'success');
                                           //                util.message('删除成功', 'refresh', 'success');
                                       }else{
                                           util.message('更新失败', '', 'error');
                                           $('#ajaxForm')[0].reset();
                                       }
                                   });
                           }else{
                               $('#ajaxForm')[0].reset();
                           }
                       })
                   })

               </script>
               {/if}